import sys
sys.path.append(".")
sys.path.append('..')

from lib.metrics.metrics import metric
from lib.data import Dataset
from utils import get_logger
import os
import numpy as np


class ImputeBase:
    def __init__(self, **kwargs):
        self.kwargs = kwargs
        self.method = ''

        self.indicators = kwargs['indicators']
        self.masked_indicator = kwargs['masked_indicator']
        self.seq_len = kwargs['seq_len']
        self.dataset = Dataset(kwargs['data_name'], kwargs['data_type'], kwargs['seq_len'], kwargs['indicators'], kwargs['masked_indicator'])
        self.ori_data = self.dataset.load_ori_data()
        self.masked_data = self.dataset.load_masked_data()

    @property
    def log_dir(self):
        log_dir = os.path.join('output', 'impute', self.indicators.split(',')[-1], self.method)
        return log_dir

    @property
    def logger(self):
        return get_logger(self.log_dir, self.log_dir, 'impute.log')

    def impute(self):
        # 插值
        pass

    def devide_window(self, data):
        # 重新窗口化
        windowed_data = []
        for i in range(0, len(data) - self.seq_len):
            _x = data[i:i + self.seq_len]
            windowed_data.append(_x)
        return np.asarray(windowed_data)

    def metirc(self):
        self.logger.info(self.kwargs)
        impute_data = self.impute()
        ori_data = self.ori_data[:len(impute_data)]
        metric_results = metric(ori_data, impute_data, self.logger)
        msg = 'discriminative:{:.4f},predictive:{:.4f},mae:{:.4f}'\
            .format(metric_results['discriminative'], metric_results['predictive'], metric_results['mae'])
        self.logger.info(msg)


